package com.ptmall.app.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;

import com.ptmall.app.MainActivity;
import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.bean.HomePageArea;
import com.ptmall.app.bean.PageData;
import com.ptmall.app.bean.ProductBean;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.ui.adapter.GoodListAdapter;
import com.ptmall.app.ui.adapter.HomePageAreaListAdapter;
import com.ptmall.app.ui.adapter.LikeGoodAdapter;
import com.ptmall.app.utils.SharedPreferencesHelper;
import com.ptmall.app.view.PullToRefreshLayout;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2019/1/24.
 */

public class SeachGoodActivity extends BaseMvpActivity {

    GridView gridView;

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();
    EditText seach_edit;
    ImageView seach;
    LikeGoodAdapter mGoodListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_seachgood);
    }

    @Override
    public void initViews() {
        gridView = (GridView) findViewById(R.id.gridview);
        seach_edit = (EditText) findViewById(R.id.seach_edit);
        seach = (ImageView) findViewById(R.id.seach);
    }

    @Override
    public void initEvents() {
        mGoodListAdapter = new LikeGoodAdapter(getContext(), null);
        gridView.setAdapter(mGoodListAdapter);
        seach.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getdata();
            }
        });
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        getdata();
    }


    private void getdata() {
        Map<String, String> map = new HashMap<>();
        map.put("keyword", seach_edit.getText().toString());
        apiDataRepository.getSeachGood(map, new ApiNetResponse<PageData<ProductBean>>(getContext()) {
            @Override
            public void onSuccess(PageData<ProductBean> data) {
                mGoodListAdapter.pushData(data.getData());
            }
        });
    }


}
